;*****************************************************
; 	Copyright (C) SEIKO EPSON CORP. 1997-2001
;	All rights Reserved
;
;	File name : memchr.s
;	Function  :
;	       This is memchr function
;	Revision  :
;		1997/03/25	V.Chan start
;		2001/12/06	T.Tazaki for GNU33(Linux)
;*****************************************************

;*****************************************************
; memchr
;		find first occurrence of char in the
;		first N bytes of src
;		return	: addr of char
;				: NULL if not found
;
; arguments : %r6:src addr, %r7:char, %r8:byte number
; return    : %r4:located char addr
;*****************************************************

	.section .text
	.align 1
	.global memchr
	.type	 memchr,@function

memchr:
	ld.w	%r4, 0			; initialize as NULL
			
memchr_loop:
	cmp		%r8, 0
	jreq	memchr_ret
	ld.ub	%r10, [%r6]+	; load byte
	cmp		%r10, %r7
	jrne.d	memchr_loop
	sub		%r8, 1

	sub		%r6, 1			; move back 1 byte
	ld.w	%r4, %r6		; addr of char

memchr_ret:
	ret

